package com.ttx.rabbitmq.demo.mq2.batch;

import com.ttx.rabbitmq.demo.config.RabbitMqConfig2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.BatchMessageListener;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author
 * @date
 */
@Slf4j
@Component
public class BatchQueueListener implements BatchMessageListener {

    //批量接收处理
    @RabbitListener(queues = RabbitMqConfig2.BATCH_QUEUE_NAME,containerFactory = "batchQueueRabbitListenerContainerFactory")
    @Override
    public void onMessageBatch(List<Message> messages) {
        log.info("batch.queue.consumer 收到{}条message", messages.size());
        if(messages.size()>0){
            log.info("第一条数据是: {}", new String(messages.get(0).getBody()));
        }
    }
}
